package ar.edu.unicen.pladema.vc1.practico2;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;

import ar.edu.unicen.pladema.main.SWTUtils;
import ar.edu.unicen.pladema.ui.model.points.ScreenPoint;
import ar.edu.unicen.pladema.ui.mouseListener.VCMouseListener;
import ar.edu.unicen.pladema.ui.panel.AbstractPanel;
import ar.edu.unicen.pladema.ui.panel.options.IMoveIt;
import ar.edu.unicen.pladema.ui.panel.options.IPaintIt;
import ar.edu.unicen.pladema.ui.panel.options.IZoomIt;
import ar.edu.unicen.pladema.ui.panel.options.POP2E3;
import ar.edu.unicen.pladema.vc1.model.GraphicAttributes;

public class P2Enunciado3 extends AbstractPanel implements IPaintIt, IMoveIt, IZoomIt {
	private Composite lienzo;
	private P2Enunciado3Drawer listener;
	private POP2E3 pOpciones;
	private GraphicAttributes graphicAttributes; 

	public P2Enunciado3(Composite parent) {
		super(parent);
	}

	@Override
	protected void createWidgets() {
		graphicAttributes = new GraphicAttributes();
		graphicAttributes.add(GraphicAttributes.ZOOM, 100)
			.add(GraphicAttributes.OFFSET_X, 0)
			.add(GraphicAttributes.OFFSET_Y, 0)
			.add(GraphicAttributes.SIZE_WIDTH,0)
			.add(GraphicAttributes.SIZE_HEIGHT,0)
			.add(GraphicAttributes.LAST_ACTION, "ASTART")
			.add(GraphicAttributes.MAX_ITERATIONS, 255);
		pOpciones = new POP2E3(this, this, graphicAttributes);
		lienzo = new Composite(this, SWT.BORDER);
		listener = new P2Enunciado3Drawer(graphicAttributes);
		pOpciones.setColorRange(listener.testPaleta());
		lienzo.addPaintListener(listener);
		lienzo.addMouseListener(new VCMouseListener(this, this, this));
	}
	
	@Override
	protected void layoutWidgets() {
		setLayout(new FormLayout());
		FormData fdLienzo = SWTUtils.createFullLeftFormData(pOpciones);
		fdLienzo.bottom = new FormAttachment(SWTUtils.MAX_FORMDATA_COORD);
		lienzo.setLayoutData(fdLienzo);
		FormData fdOpciones = SWTUtils.createRightFormData(5);
		fdOpciones.bottom = new FormAttachment(SWTUtils.MAX_FORMDATA_COORD);
		pOpciones.setLayoutData(fdOpciones);
	}

	@Override
	public void doPaint() {
		//listener.setBounds(pOpciones.getWidth(), pOpciones.getHeight());
		listener.setColorRange(pOpciones.getColorRange());
		lienzo.redraw();
	}

	@Override
	public void doMove(ScreenPoint from, ScreenPoint to) {
		listener.doMove(from, to);
	}

	@Override
	public void doZoom(ScreenPoint from, ScreenPoint to) {
		//int coorX = graphicAttributes.getInt(GraphicAttributes.OFFSET_X);
		//int coorY = graphicAttributes.getInt(GraphicAttributes.OFFSET_Y);
		
		ScreenPoint upleftPoint = from.lowerPoint(to);
		ScreenPoint bottomrightPoint = from.upperPoint(to);
		
		listener.doZoom(upleftPoint, bottomrightPoint);
	}

	@Override
	public void doZoom(boolean in) {
		// TODO Auto-generated method stub
		
	}

}
